let initState = {
    list: [
        {
            id: 0,
            name: '闲人一枚',
            isGuanzhu: false,
            img: '/images/0.jpg',
            zym: '哈哈哈...',
            msg: [
                { wz: 'left', nr: '你好呀' },
                { wz: 'right', nr: '嗨~你好呀' }
            ]
        },
        {
            id: 1,
            name: '小猪佩奇',
            isGuanzhu: true,
            img: '/images/1.jpg',
            zym: '哈哈哈2222...',
            msg: [
                { wz: 'left', nr: '你吃了吗' },
                { wz: 'right', nr: '我还没吃呢' }
            ]
        }
    ]
}
export default function reducer(prevState = initState, action) {
    let { type, data } = action;
    let newState = JSON.parse(JSON.stringify(prevState))
    switch (type) {
        case 'tab':
            let { id, isGuanzhu } = data;
            // newState.list[index].isGuanzhu = isGuanzhu
            newState.list.forEach((item, index) => {
                if (item.id === id) {
                    item.isGuanzhu = isGuanzhu
                }
            })
            return newState
        case 'send':
            newState.list.forEach((item, index) => {
                if (item.id === data.id) {
                    item.msg.push({ wz: 'right', nr: data.txt })
                }
            })
            // console.log(newState);
            return newState
        default:
            return prevState
    }
}